package com.ruoyi.system.outto.goods.impl;

import com.alibaba.fastjson.JSONObject;
import com.ruoyi.common.constant.Constants;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.exception.GlobalException;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.common.utils.http.HttpUtils;
import com.ruoyi.system.V2.gameAttr.mapper.GameAttributeMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoImgMapper;
import com.ruoyi.system.V2.goodInfo.mapper.GoodsInfoMapper;
import com.ruoyi.system.V2.inter.mapper.ArtRecMapper;
import com.ruoyi.system.model.domain.*;
import com.ruoyi.system.model.dto.GoodsInfoAndAttrValueDto;
import com.ruoyi.system.model.mapper.*;
import com.ruoyi.system.outto.core.BQWConstan;
import com.ruoyi.system.outto.core.LCConstant;
import com.ruoyi.system.outto.core.MapUntils;
import com.ruoyi.system.outto.game.CommonApi;
import com.ruoyi.system.outto.goods.NEWBQWAPI;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.beanutils.ConvertUtils;
import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.math.BigDecimal;
import java.util.*;
import java.util.stream.Collectors;

/**
 * @author lz
 * @version 1.0
 * @date 2022/6/5 16:19
 */
@Slf4j
@Service
public class NEWBQWAPIImpl implements NEWBQWAPI {

    @Resource
    private InfoImgMapper infoImgMapper;
    @Resource
    private AccountInfoMapper accountInfoMapper;
    @Resource
    private SuprAuthMapper suprAuthMapper;
    @Resource
    private CommonApi commonApi;
    @Value("${desc.title}")
    private String descTitle;
    private SalePartner salePartner;
    @Resource
    private GoodsInfoMapper goodsInfoMapper;
    @Resource
    private GoodsInfoImgMapper goodsInfoImgMapper;
    @Resource
    private GameAttributeMapper gameAttributeMapper;
    @Resource
    private ArtRecMapper artRecMapper;

    static String Token = "fc25d908ec6111e5";
    static String ServiceName = "zhanghao";


    @Override
    public AjaxResult addGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        this.salePartner = salePartner;
        String url = "http://a.baqiwan1.com/docking/game/account";

//        http://a.baqiwan1.com/
        Map<String, Object> head = new HashMap<>();
        head.put("Token", salePartner.getSaleKey());
        head.put("Service-Name", salePartner.getOther());
//        head.put("Token", Token);
//        head.put("Service-Name", ServiceName);

        this.salePartner = salePartner;
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, "add");
        log.info("霸气玩添加接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.doPostForm(salePartner.getTwoOther(), params, head);
        log.info("霸气玩添加接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);
        if (!"1".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            JSONObject data = resultJson.getJSONObject("data");
            String res_id = data.getString("res_id");
            ArtRec artRecreq = new ArtRec();
            artRecreq.setConfig(salePartner.getId());
            artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
            List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
            if(artRecs.size()>0) {
                artRecs.get(0).setOutid(res_id);
                artRecMapper.updateArtRec(artRecs.get(0));
            }else{
                artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
                artRecreq.setCreateId(goodsInfoAndAttrValueDto.getCreateId());
                artRecreq.setType(LCConstant.interAdd);
                artRecreq.setConfig(salePartner.getId());
                artRecreq.setSaleCode(salePartner.getSaleName());
                artRecreq.setOutid(res_id);
                artRecMapper.insertArtRec(artRecreq);
            }
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("data"));
        return AjaxResult.success(result);
    }

    @Override
    public AjaxResult editGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner salePartner) {
        this.salePartner = salePartner;
//        String url = "https://a.baqiwan1.com/docking/game/account";
        String url = "http://a.baqiwan1.com/docking/game/account";

        Map<String, Object> head = new HashMap<>();
        head.put("Token", salePartner.getSaleKey());
        head.put("Service-Name", salePartner.getOther());

//        head.put("Token", Token);
//        head.put("Service-Name", ServiceName);

        this.salePartner = salePartner;
        Map<String, Object> result = new HashMap<>();
        Map<String, Object> params = params(goodsInfoAndAttrValueDto, "edit");
        log.info("霸气玩编辑接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.doPostForm(salePartner.getTwoOther(), params, head);
        log.info("霸气玩编辑接口返回参数={}", response);
        JSONObject resultJson = JSONObject.parseObject(response);

        //{"code":1,"msg":"添加成功","time":1676002262,"data":{"res_id":"105042"}}

        if (!"1".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("msg"));
        return AjaxResult.success(result);
    }



    @Override
    public AjaxResult delGame(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, SalePartner sa) {
        Map<String, Object> params = new TreeMap<>();
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(sa.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        if(artRecs.size()<0){
            throw new GlobalException("当前账号未推送，不可删除");
        }
        params.put("account_id", artRecs.get(0).getOutid());
        params.put("act","del");
//        String url = "https://a.baqiwan1.com/docking/game/account";
        String url = "http://a.baqiwan1.com/docking/game/account";

        String path = "/docking/game/account";

        Map<String, Object> head = new HashMap<>();
        head.put("Token", sa.getSaleKey());
        head.put("Service-Name", sa.getOther());

//        head.put("Token", Token);
//        head.put("Service-Name", ServiceName);

        //sign
        String cover = MapUntils.getCover(params);
//        cover = cover + "key=" + Token;
        cover = cover + "key=" + sa.getSaleKey();
        String sign = DigestUtils.md5Hex(cover);
        params.put("sign", sign);
        log.info("霸气玩删除接口请求参数={}", JSONObject.toJSONString(params));
        String response = HttpUtils.doPostForm(sa.getTwoOther(), params, head);
        log.info("霸气玩删除接口返回参数={}", JSONObject.toJSONString(response));
        JSONObject resultJson = JSONObject.parseObject(response);
        Map<String, Object> result = new HashMap<>();

        if (!"1".equals(resultJson.getString("code"))) {
            result.put("code", 500);
        } else {
            result.put("code", 200);
            ArtRec artRecreq1 = new ArtRec();
            artRecreq1.setConfig(salePartner.getId());
            artRecreq1.setAccountId(goodsInfoAndAttrValueDto.getId());
            List<ArtRec> artRecs1 = artRecMapper.selectArtRecList(artRecreq1);
            if(artRecs1.size()>0) {
                artRecMapper.deleteArtRecById(artRecs1.get(0).getId());
            }
        }

        result.put("req", JSONObject.toJSONString(params));
        result.put("res", response);
        result.put("msg", resultJson.getString("data"));
        return AjaxResult.success(result);
    }


    private Map<String, Object> params(GoodsInfoAndAttrValueDto goodsInfoAndAttrValueDto, String type) {

        String des = goodsInfoAndAttrValueDto.getDes().replace("+","");
        GameAttribute gameAttribute = null;
        if(goodsInfoAndAttrValueDto.getGameName().contains("王者荣耀")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("和平精英")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("原神")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("穿越火线")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("光遇")){//=================================未配置游戏属性
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("英雄联盟")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF1()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("火影忍者")){//=================================未配置游戏属性
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF20()));
        }else if(goodsInfoAndAttrValueDto.getGameName().contains("枪战王者")){
            gameAttribute = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
        }else{
            throw new GlobalException("当前游戏暂不支持");
        }
        goodsInfoAndAttrValueDto.setDes(descTitle + "||" + goodsInfoAndAttrValueDto.getId() + " " + goodsInfoAndAttrValueDto.getGameName() + " " + gameAttribute.getFieldName() + " " + des);

        Map<String, Object> params = new TreeMap<>();
        params.put("title", goodsInfoAndAttrValueDto.getDes());
        params.put("description", goodsInfoAndAttrValueDto.getDes());
        String titleImg = goodsInfoAndAttrValueDto.getTitleImg();
        if (StringUtils.isNotEmpty(titleImg)) {
            params.put("img", titleImg);
        } else {
            params.put("img", LCConstant.defaultImg);
        }
        GoodsInfoImg goodsInfoImg = new GoodsInfoImg();
        goodsInfoImg.setGoodsId(goodsInfoAndAttrValueDto.getId());
        goodsInfoImg.setType(Constants.STR_1);
        List<GoodsInfoImg> infoImgs = goodsInfoImgMapper.selectGoodsInfoImgList(goodsInfoImg);

        String imgs = "";
        if (Objects.nonNull(goodsInfoAndAttrValueDto.getTitleImg())) {
            imgs = goodsInfoAndAttrValueDto.getTitleImg() + ",";
        }
        if (!CollectionUtils.isEmpty(infoImgs)) {
            imgs = imgs + infoImgs.stream().map(i -> i.getImgUrl()).collect(Collectors.joining(","));
        } else {
            imgs = imgs + LCConstant.defaultImg;
        }


        params.put("imgs", imgs);
        params.put("account_number", descTitle + "||" + goodsInfoAndAttrValueDto.getId());
//        String string = accountInfo.getPrice().stripTrailingZeros().toPlainString();
        BigDecimal bigDecimal = commonApi.addPrice(goodsInfoAndAttrValueDto.getPrice(), this.salePartner.getSeleep());
        commonApi.setPrice(bigDecimal,goodsInfoAndAttrValueDto.getId(),this.salePartner);
        params.put("price", bigDecimal.stripTrailingZeros().toPlainString());

        params.put("act", type);
//        params.put("account_id",accountInfo.getId());

        if (Objects.equals("英雄联盟", goodsInfoAndAttrValueDto.getGameName())) {
            params.put("game_id", 1);
            params.put("area", goodsInfoAndAttrValueDto.getGroupName());
            JSONObject json = new JSONObject();
            List<String> ffs = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF8())) {
                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF8());
                for(GameAttribute gameAttribute1 : gameAttributes) {
                    for (String str : BQWConstan.zzstrs) {
                        if (gameAttribute1.getFieldName().contains(str.replace("至臻", ""))) {
                            ffs.add(str);
                        }
                    }
                }
            }
            if(ffs.size()>0) {
                String join = StringUtils.join(ffs, ",");
                json.put("zz", join);
            }
            List<String> hks = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF9())) {
                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF9());
                for(GameAttribute gameAttribute1 : gameAttributes) {
                    for (String str : BQWConstan.hks) {
                        if (gameAttribute1.getFieldName().contains(str.replace("鳄鱼","雷克顿").replace("马尔扎哈","玛尔扎哈"))) {
                            hks.add(str);
                        }
                    }
                }
            }
            if(hks.size()>0) {
                String join = StringUtils.join(hks, ",");
                json.put("hks", join);
            }
            List<String> rm = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF7())) {
                String pfIds = "";
                pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF7());
                pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF10());
                List<GameAttribute> gameAttributes = getGameAttributs(pfIds);
                for(GameAttribute gameAttribute1 : gameAttributes) {
                    for (String str : BQWConstan.rm) {
                        if (gameAttribute1.getFieldName().contains(str.replace("龙的传人","龙年盲僧"))) {
                            rm.add(str);
                        }
                    }
                }
            }
            if(rm.size()>0) {
                String join = StringUtils.join(rm, ",");
                json.put("rm", join);
            }

            json.put("yxlm_yxsl", goodsInfoAndAttrValueDto.getF3());
            json.put("yxlm_pfsl", goodsInfoAndAttrValueDto.getF4());
            params.put("data", json);
        }

        if (Objects.equals("王者荣耀", goodsInfoAndAttrValueDto.getGameName())) {
            params.put("game_id", 2);
            String area = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            params.put("area", area.replace("QQ","qq"));
//            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
//                params.put("area", "安卓微信");
//            }
//            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
//                params.put("area", "安卓qq");
//            }
//            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
//                params.put("area", "苹果微信");
//            }
//            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
//                params.put("area", "苹果qq");
//            }

            JSONObject json = new JSONObject();
            List<String> yingxiong = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF5())) {
                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF5());
                for (GameAttribute gameAttribute1 : gameAttributes) {
                    for (String str : BQWConstan.yingxiong) {
                        if (gameAttribute1.getFieldName().contains(str)) {
                            yingxiong.add(str);
                        }
                    }
                }
            }
            if(yingxiong.size()>0) {
                String join = StringUtils.join(yingxiong, ",");
                json.put("yingxiong", join);
            }
            List<String> shuijing = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF9())) {
                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF9());
                for (GameAttribute gameAttribute1 : gameAttributes) {
                    for (String str : BQWConstan.shuijing) {
                        if (gameAttribute1.getFieldName().contains(str)) {
                            shuijing.add(str);
                        }
                    }
                }
            }
            if(shuijing.size()>0) {
                String join = StringUtils.join(shuijing, ",");
                json.put("shuijing", join);
            }
            List<String> xingyuan = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF10())) {
                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF10());
                for (GameAttribute gameAttribute1 : gameAttributes) {
                    for (String str : BQWConstan.xingyuan) {
                        if (gameAttribute1.getFieldName().contains(str)) {
                            xingyuan.add(str);
                        }
                    }
                }
            }
            if(xingyuan.size()>0) {
                String join = StringUtils.join(xingyuan, ",");
                json.put("xingyuan", join);
            }
            List<String> xdpf = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF11())) {
                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF11());
                for (GameAttribute gameAttribute1 : gameAttributes) {
                    for (String str : BQWConstan.xdpf) {
                        if (gameAttribute1.getFieldName().contains(str)) {
                            xdpf.add(str);
                        }
                    }
                }
            }
            if(xdpf.size()>0) {
                String join = StringUtils.join(xdpf, ",");
                json.put("xdpf", join);
            }
            List<String> chuanshuo = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF12())) {
                String fildName = "";
                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF12());
                for (GameAttribute gameAttribute1 : gameAttributes) {
                    if(gameAttribute1.getFieldName().contains("小乔-音你心动")){
                        fildName = "音你心动女";
                    }else if(gameAttribute1.getFieldName().contains("周瑜-音你心动")){
                        fildName = "音你心动男";
                    }else{
                        fildName = gameAttribute1.getFieldName();
                    }
                    for (String str : BQWConstan.chuanshuo) {
                        if (fildName.contains(str)) {
                            chuanshuo.add(str);
                        }
                    }
                }
            }
            if(chuanshuo.size()>0) {
                String join = StringUtils.join(chuanshuo, ",");
                json.put("chuanshuo", join);
            }

            GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF16()));
            String level = gameAttribute1.getFieldName();
            if ("可二次实名".contains(level)) {
                json.put("bface", "包");
            } else {
                json.put("bface", "不包");
            }

            json.put("wzry_yxsl", goodsInfoAndAttrValueDto.getF7());
            json.put("wjmwsl", 0);
            json.put("gzdj", 0);
            json.put("gzjf", 0);
            params.put("data", json);
        }


        if (Objects.equals("穿越火线", goodsInfoAndAttrValueDto.getGameName())) {
            params.put("game_id", 3);

//            String[] cfRe = {"河南大区【北部】",
//                    "北京大区【北部】",
//                    "山东大区【北部】",
//                    "河北大区【北部】",
//                    "山西大区【北部】",
//                    "辽宁大区【北部】",
//                    "北方大区【北部】",
//                    "吉林大区【北部】",
//                    "黑龙江区【北部】",
//                    "福建大区【东部】",
//                    "安徽大区【东部】",
//                    "上海大区【东部】",
//                    "浙江大区【东部】",
//                    "江苏大区【东部】",
//                    "江西大区【南部】",
//                    "南方大区【南部】",
//                    "湖南大区【南部】",
//                    "湖北大区【南部】",
//                    "广东大区【南部】",
//                    "广西大区【南部】",
//                    "四川大区【西部】",
//                    "重庆大区【西部】",
//                    "云南大区【西部】",
//                    "陕西大区【西部】"};
//
//            for (String reStr : cfRe) {
//                String re = reStr.split("-")[0];
//                if (re.length() > 2) {
//                    String substring = re.substring(0, 2);
//                    if (accountInfo.getDes().contains(substring)) {
//                        params.put("area", reStr);
//                        break;
//                    }
//                }
//            }
            String area = goodsInfoAndAttrValueDto.getServerName().replace("一","大").replace("二","大").replace("三","大");
            if(goodsInfoAndAttrValueDto.getGroupName().contains("黑龙江")){
                area = area+"【"+goodsInfoAndAttrValueDto.getGroupName().substring(0,3)+"】";
            }else{
                area = area+"【"+goodsInfoAndAttrValueDto.getGroupName().substring(0,2)+"】";
            }
            params.put("area",area);

            JSONObject json = new JSONObject();
            List<String> wzxjwq = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF14())) {
                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF14());
                for(GameAttribute gameAttribute1: gameAttributes) {
                    for (String str : BQWConstan.wzxjwq) {
                        if (gameAttribute1.getFieldName().contains(str)) {
                            wzxjwq.add(str);
                        }
                    }
                }
            }
            String join = StringUtils.join(wzxjwq, ",");
            json.put("wzxjwq", join);

//            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF13())) {
//                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF13());
//            }
//            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF14())) {
//                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF14());
//            }
//            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF15())) {
//                List<GameAttribute> gameAttributes = getGameAttributs(goodsInfoAndAttrValueDto.getF15());
//            }


            String wqIds = "";
            wqIds = reIds(wqIds, goodsInfoAndAttrValueDto.getF13());
            wqIds = reIds(wqIds, goodsInfoAndAttrValueDto.getF14());
            wqIds = reIds(wqIds, goodsInfoAndAttrValueDto.getF15());
            List<GameAttribute> gameAttributes = getGameAttributs(wqIds);
            List<String> rmwq = new ArrayList<>();
            for(GameAttribute gameAttribute1 :gameAttributes) {
                for (String str : BQWConstan.rmwq) {
                    if (gameAttribute1.getFieldName().contains(str)) {
                        rmwq.add(str);
                    }
                }
            }
            if(rmwq.size()>0) {
                join = StringUtils.join(rmwq, ",");
                json.put("rmwq", join);
            }

            String pfIds = "";
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF16());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF17());
            pfIds = reIds(pfIds, goodsInfoAndAttrValueDto.getF18());
            List<GameAttribute> gameAttributess = getGameAttributs(pfIds);
            List<String> rmpf = new ArrayList<>();
            for(GameAttribute gameAttribute1 :gameAttributess) {
                for (String str : BQWConstan.rmpf) {
                    if (gameAttribute1.getFieldName().contains(str)) {
                        rmpf.add(str);
                    }
                }
            }
            if(rmpf.size()>0) {
                join = StringUtils.join(rmpf, ",");
                json.put("rmpf", join);
            }

            List<GameAttribute> gameAttributesss = getGameAttributs(goodsInfoAndAttrValueDto.getF20());
            List<String> rmdj = new ArrayList<>();
            for(GameAttribute gameAttribute1 : gameAttributesss) {
                for (String str : BQWConstan.rmdj) {
                    if (gameAttribute1.getFieldName().contains(str)) {
                        rmdj.add(str);
                    }
                }
            }
            if(rmdj.size()>0) {
                join = StringUtils.join(rmdj, ",");
                json.put("rmdj", join);
            }

//            for (String str : BQWConstan.chuanshuo) {
//                if (goodsInfoAndAttrValueDto.getDes().contains(str)) {
//                    ffs.add(str);
//                }
//            }
//            join = StringUtils.join(ffs, ",");
//            json.put("chuanshuo", join);
            GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF3()));
            String level = gameAttribute1.getFieldName();
            if ("有修改机会且实名是本人".contains(level)) {
                json.put("rcsm", "有");
            } else {
                json.put("rcsm", "无");
            }
            json.put("pwszg", "有");
            json.put("hero_weapon", goodsInfoAndAttrValueDto.getF11());
            params.put("data", json);
        }

        if (Objects.equals("原神", goodsInfoAndAttrValueDto.getGameName())) {
            params.put("game_id", 3);
            params.put("area", "米哈游");

            JSONObject json = new JSONObject();
            List<String> ffs = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF11())) {
                List<GameAttribute> gameAttributesss = getGameAttributs(goodsInfoAndAttrValueDto.getF11());
                for(GameAttribute gameAttribute1: gameAttributesss) {
                    for (String str : BQWConstan.wxyxa) {
                        if (gameAttribute1.getFieldName().contains(str)) {
                            ffs.add(str);
                        }
                    }
                }
            }
            String join = StringUtils.join(ffs, ",");
            json.put("wxyxa", join);
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF17())) {
                List<GameAttribute> gameAttributesss = getGameAttributs(goodsInfoAndAttrValueDto.getF17());
                for(GameAttribute gameAttribute1 : gameAttributesss) {
                    for (String str : BQWConstan.wxwq) {
                        if (gameAttribute1.getFieldName().contains(str)) {
                            ffs.add(str);
                        }
                    }
                }
            }
            join = StringUtils.join(ffs, ",");
            json.put("wxwq", join);

            params.put("data", json);
        }

        if (Objects.equals("和平精英", goodsInfoAndAttrValueDto.getGameName())) {

            params.put("game_id", 5);
            String area = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            params.put("area", area.replace("QQ","qq"));
//            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
//                params.put("area", "安卓微信");
//            }
//            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
//                params.put("area", "安卓qq");
//            }
//            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
//                params.put("area", "苹果微信");
//            }
//            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
//                params.put("area", "苹果qq");
//            }

            JSONObject json = new JSONObject();
            List<String> ffs = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF2())) {
                List<GameAttribute> gameAttributesss = getGameAttributs(goodsInfoAndAttrValueDto.getF2());
                for(GameAttribute gameAttribute1 : gameAttributesss) {
                    for (String str : BQWConstan.zj) {
                        if (gameAttribute1.getFieldName().replace("-","").contains(str)) {
                            ffs.add(str);
                        }
                    }
                }
            }
            String join = StringUtils.join(ffs, ",");
            json.put("zj", join);

            ffs = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF1())) {
                List<GameAttribute> gameAttributesss = getGameAttributs(goodsInfoAndAttrValueDto.getF1());
                for(GameAttribute gameAttribute1 : gameAttributesss) {
                    for (String str : BQWConstan.tx) {
                        if (gameAttribute1.getFieldName().contains(str.replace("枪械",""))) {
                            ffs.add(str);
                        }
                    }
                }
            }
            if(ffs.size()>0) {
                join = StringUtils.join(ffs, ",");
                json.put("tx", join);
            }

            ffs = new ArrayList<>();
            if(StringUtils.isNotEmpty(goodsInfoAndAttrValueDto.getF5())) {
                List<GameAttribute> gameAttributesss = getGameAttributs(goodsInfoAndAttrValueDto.getF5());
                for(GameAttribute gameAttribute1 : gameAttributesss) {
                    for (String str : BQWConstan.yztz) {
                        if (gameAttribute1.getFieldName().contains(str)||str.contains(gameAttribute1.getFieldName())) {
                            ffs.add(str);
                        }
                    }
                }
            }
            if(ffs.size()>0) {
                join = StringUtils.join(ffs, ",");
                json.put("yztz", join);
            }
            GameAttribute gameAttribute1 = gameAttributeMapper.selectGameAttributeById(Long.valueOf(goodsInfoAndAttrValueDto.getF10()));
            if ("可二次实名".contains(gameAttribute1.getFieldName())) {
                json.put("hpjy_bface", "包");
            } else {
                json.put("hpjy_bface", "不包");
            }
            json.put("hpjy_tzsl", goodsInfoAndAttrValueDto.getF8());
            json.put("hpjy_qpsl", goodsInfoAndAttrValueDto.getF9());
            json.put("hpjy_zjsl", 0);
            params.put("data", json);
        }

        if (Objects.equals("枪战王者", goodsInfoAndAttrValueDto.getGameName())) {
            String area = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            params.put("area", area.replace("QQ","qq"));
            params.put("game_id", 7);
//
//            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
//                params.put("area", "安卓微信");
//            }
//            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
//                params.put("area", "安卓qq");
//            }
//            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
//                params.put("area", "苹果微信");
//            }
//            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
//                params.put("area", "苹果qq");
//            }

            JSONObject json = new JSONObject();
            json.put("wztz","");
            json.put("wzwqq","");
            json.put("xywqq","");
            json.put("yxtz","");
            json.put("jss","");
            json.put("yxk","");
            params.put("data", json);
        }

        if (Objects.equals("逆战", goodsInfoAndAttrValueDto.getGameName())) {

            params.put("game_id", 8);
            params.put("area", goodsInfoAndAttrValueDto.getServerName());

            JSONObject json = new JSONObject();
            json.put("tz","");
            json.put("js","");
            json.put("wq","");
            json.put("djcw","");
            params.put("data", json);
        }

        if (Objects.equals("火影忍者", goodsInfoAndAttrValueDto.getGameName())) {

            params.put("game_id", 9);
            String area = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            params.put("area", area.replace("QQ","qq"));
//            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
//                params.put("area", "安卓微信");
//            }
//            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
//                params.put("area", "安卓qq");
//            }
//            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
//                params.put("area", "苹果微信");
//            }
//            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
//                params.put("area", "苹果qq");
//            }

            JSONObject json = new JSONObject();
            json.put("s_renzhe","");
            json.put("a_jirenzhe","");
            params.put("data", json);
        }


        if (Objects.equals("QQ飞车手游", goodsInfoAndAttrValueDto.getGameName())) {

            params.put("game_id", 10);

//            if (Objects.equals("安卓WX", accountInfo.getRegional())) {
//                params.put("area", "安卓微信");
//            }
//            if (Objects.equals("安卓Q", accountInfo.getRegional())) {
//                params.put("area", "安卓qq");
//            }
//            if (Objects.equals("苹果WX", accountInfo.getRegional())) {
//                params.put("area", "苹果微信");
//            }
//            if (Objects.equals("苹果Q", accountInfo.getRegional())) {
//                params.put("area", "苹果qq");
//            }
            String area = goodsInfoAndAttrValueDto.getSystemName()+goodsInfoAndAttrValueDto.getCarrierName();
            params.put("area", area.replace("QQ","qq"));
            JSONObject json = new JSONObject();
            params.put("data", json);
        }
        ArtRec artRecreq = new ArtRec();
        artRecreq.setConfig(salePartner.getId());
        artRecreq.setAccountId(goodsInfoAndAttrValueDto.getId());
        List<ArtRec> artRecs = artRecMapper.selectArtRecList(artRecreq);
        if(artRecs.size()>0) {
            if (StringUtils.isNotEmpty(artRecs.get(0).getOutid())) {
                params.put("account_id", artRecs.get(0).getOutid());
            } else {
                params.put("account_id", "");
            }
        }else{
            params.put("account_id", "");
        }
        String cover = MapUntils.getCover(params);
        cover = cover + "key=" + salePartner.getSaleKey();
//        cover = cover + "key=" + Token;
        System.out.println(cover);
        String sign = DigestUtils.md5Hex(cover);
        log.info("sign={}", sign);
        params.put("sign", sign);
        return params;
    }

    private String reIds(String allIds, String ids) {
        if (StringUtils.isNotEmpty(ids)) {
            if (StringUtils.isNotEmpty(allIds)) {
                allIds = allIds + "," + ids;
            } else {
                allIds = ids;
            }
        }
        return allIds;
    }

    private List<GameAttribute> getGameAttributs(String ids) {
        return gameAttributeMapper.selectGameAttributeListByIds((Long[]) ConvertUtils.convert(ids.split(","),
                Long.class));
    }


    public static void main(String[] args) {

//        Token:fc25d908ec6111e5
//        Service-Name:zhanghao


        Map<String, Object> params = new HashMap<>();
        //游戏类型参数
        params.put("game_id", 5);


        String cover = MapUntils.getCover(params);
        //转换参数是空时，使用这个
//        cover = cover + "&key=" + Token;
        cover = cover + "key=" + Token;
        System.out.println(cover);
        String sign = DigestUtils.md5Hex(cover);
        params.put("sign", sign);

//        String gameLists = HttpUtils.sendGetBQW("https://a.baqiwan.com/docking/game/gameLists?sign=" + sign, null, Constants.UTF8, Token, ServiceName);
//        System.out.println(gameLists);
        //游戏列表
        //{"code":1,"msg":"游戏列表","time":1675838558,"data":[{"id":1,"title":"英雄联盟"},{"id":2,"title":"王者荣耀"},{"id":3,"title":"穿越火线"},{"id":4,"title":"原神"},{"id":5,"title":"和平精英"},{"id":6,"title":"QQ飞车"},{"id":7,"title":"枪战王者"},{"id":8,"title":"逆战"},{"id":9,"title":"火影忍者"},{"id":10,"title":"QQ飞车手游"},{"id":12,"title":"炉石传说"},{"id":14,"title":"球球大作战"},{"id":16,"title":"第五人格"},{"id":19,"title":"使命召唤"},{"id":20,"title":"崩坏3"},{"id":21,"title":"绝地求生"},{"id":27,"title":"守望先锋"},{"id":30,"title":"坦克世界"},{"id":31,"title":"航海王"},{"id":32,"title":"QQ靓号"},{"id":34,"title":"大话西游手游"},{"id":35,"title":"魔兽怀旧服"},{"id":37,"title":"三国杀OL"},{"id":38,"title":"三国杀十周年"},{"id":39,"title":"三国杀移动版"},{"id":40,"title":"FIFA OL4"},{"id":41,"title":"NBA2K OL2"},{"id":42,"title":"APEX英雄"},{"id":43,"title":"永劫无间"},{"id":44,"title":"古剑奇谭"},{"id":45,"title":"超激斗梦境"},{"id":46,"title":"哈利波特：魔法觉醒"},{"id":47,"title":"LOL手游"},{"id":48,"title":"DNF"}]}

        //获取游戏
        String url = "https://a.baqiwan.com/docking/game/getGameAreaAttrById";

        String gameLists = HttpUtils.sendGetBQW(url, MapUntils.getCover(params), Constants.UTF8, Token, ServiceName);
        System.out.println(gameLists);

    }

}
